package com.me.customize;

import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

/**
 * 自定义Timestamp转json后的格式
 * @author dong
 *
 */
public class JsonTimeStampSerializer extends JsonSerializer<Timestamp> {
	
	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	@Override
	public void serialize(Timestamp timestamp, JsonGenerator gen, SerializerProvider provider) 
			throws IOException, JsonProcessingException {
		String time = sdf.format(new Date(timestamp.getTime()));
		gen.writeString(time);
	}
}
